﻿using Microsoft.AspNetCore.Mvc;
using WMS.FC.Application.User.Interface;
using WMS.FC.Domain.DataTransferObject.User;
using WMS.FC.Domain.DomainObject.System;

namespace WMS.FC.WebApi.Controllers
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    public class UserController : BaseConroller
    {
        /// <summary>
        /// 用户服务
        /// </summary>
        protected readonly IUserService userService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userService"></param>
        public UserController(IUserService userService)
        {
            this.userService = userService;
        }

        /// <summary>
        /// 校验用户登录
        /// </summary>
        /// <param name="dTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> CheckLogin(CheckUserLoginDTO dTO)
        {
            dTO.UserInfo = new UserInfo()
            {
                UserIp = Request.HttpContext.Connection.RemoteIpAddress!.ToString(),
            };

            var response = await userService.CheckUserLogin(dTO);
            return Ok(response);
        }

        /// <summary>
        /// 校验用户登录
        /// </summary>
        /// <param name="dTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ChangePassword(ChangePwdDTO dTO)
        {
            var response = await userService.ChangePassword(dTO);
            return Ok(response);
        }
    }
}
